package com.example.homemodule.viewmodel;

import static androidx.fragment.app.FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT;

import static com.examination.mlib.constants.AllStringConstants.FAQ_QUA;
import static com.examination.mlib.constants.AllStringConstants.getQuality;
import static com.examination.mlib.constants.ClickApi.Home.click_drugstab;
import static com.examination.mlib.constants.ClickApi.Home.click_rebuylist;
import static com.examination.mlib.constants.ClickApi.Home.click_rebuymore;
import static com.examination.mlib.constants.ClickApi.Home.click_systemmessage;
import static com.examination.mlib.constants.UserInfoConstants.account_tagLoggedIn;
import static com.examination.mlib.utils.LoginThenRouterUtils.RouterBean.TYPE_ASK;
import static com.examination.mlib.utils.LoginThenRouterUtils.RouterBean.TYPE_FOLLOW;
import static com.examination.mlib.utils.LoginThenRouterUtils.RouterBean.TYPE_ORDER;
import static com.examination.mlib.utils.LoginThenRouterUtils.RouterBean.TYPE_PRESCRIPTION;
import static com.examination.mlib.utils.LoginThenRouterUtils.RouterBean.TYPE_QUALIFY;
import static com.example.homemodule.HomeUrl.getLiveVisitorRoom;

import android.Manifest;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.ViewFlipper;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.launcher.ARouter;
import com.app.hubert.guide.NewbieGuide;
import com.app.hubert.guide.core.Controller;
import com.app.hubert.guide.listener.OnGuideChangedListener;
import com.app.hubert.guide.listener.OnLayoutInflatedListener;
import com.app.hubert.guide.listener.OnPageChangedListener;
import com.app.hubert.guide.model.GuidePage;
import com.app.hubert.guide.model.HighLight;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.examination.mlib.bean.BaseBean;
import com.examination.mlib.bean.FaqEntity;
import com.examination.mlib.bean.SecretWordBean;
import com.examination.mlib.bean.UserActionEntity;
import com.examination.mlib.constants.ARouterConstants;
import com.examination.mlib.constants.AllStringConstants;
import com.examination.mlib.constants.ClickApi;
import com.examination.mlib.constants.KitArouterConstants;
import com.examination.mlib.constants.ProjectConfigure;
import com.examination.mlib.constants.UserInfoConstants;
import com.examination.mlib.dialog.commondialog.PromptDialog;
import com.examination.mlib.interfaceapi.HomeBackApi;
import com.examination.mlib.interfaceapi.MineBackApi;
import com.examination.mlib.utils.LoginThenRouterUtils;
import com.examination.mlib.view.SuspendedBallView;
import com.example.homemodule.adapter.DoctorHealthAdapter;
import com.example.homemodule.model.bean.AgencyMatterStatiesticsListBean;
import com.example.homemodule.model.bean.HomeCommodityGroupListEntity;
import com.example.homemodule.model.bean.HomepageEntity;
import com.example.homemodule.model.bean.PendingBean;
import com.example.homemodule.model.bean.PrivateDoctorEntity;
import com.example.homemodule.model.bean.ReBuyEntity;
import com.example.homemodule.model.bean.ThumbsUpBean;
import com.example.homemodule.model.bean.VisitorLiveEntity;
import com.example.homemodule.model.bean.live.LiveTabBean;
import com.example.homemodule.R;
import com.example.homemodule.adapter.BannerAutoScrollAdapter;
import com.example.homemodule.adapter.BuyDrugAdapter;
import com.example.homemodule.adapter.HomeDoctorAdapter;
import com.example.homemodule.adapter.HomeDrugVPAdapter;
import com.example.homemodule.adapter.HomeLiveAdapter;
import com.example.homemodule.databinding.NewHomeFragmentDataBinding;
import com.example.homemodule.view.dialog.DrugDialog;
import com.example.homemodule.view.dialog.PrivateDoctor;
import com.example.homemodule.listener.MyPageChangeListener;
import com.example.homemodule.model.HomeModel;
import com.example.homemodule.observable.HomeObservable;
import com.example.homemodule.view.qrcodeview.QrCodeActivity;
import com.example.homemodule.utils.HomeUtils;
import com.example.homemodule.view.ui.NewHomeDrugListFragment;
import com.example.homemodule.view.view.NoticeView;
import com.google.android.material.tabs.TabLayout;
import com.google.gson.Gson;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.yilijk.base.base.BaseViewModel;
import com.yilijk.base.network.RequestParams;
import com.yilijk.base.network.https.HttpCallBack;
import com.yilijk.base.network.https.HttpUtils;
import com.yilijk.base.utils.ALog;
import com.yilijk.base.utils.ActivityManagerUtils;
import com.yilijk.base.utils.ClickUtils;
import com.yilijk.base.utils.CommonUtils;
import com.yilijk.base.utils.DevicesUtils;
import com.yilijk.base.utils.ListUtil;
import com.yilijk.base.utils.LoadingUtils;
import com.yilijk.base.utils.ScreenUtils;
import com.yilijk.base.utils.SharedPreferencesUtils;
import com.yilijk.base.utils.ToastUtils;
import com.yilijk.base.utils.UIUtils;
import com.yilijk.base.utils.Utils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import retrofit2.http.HEAD;

/**
 * Created by SHICHENG
 * <p>
 * Time on
 */
public class HomeViewModel extends BaseViewModel<HomeModel> {


    private int changeScrollH = 120;
    private double searchHStep = 0;
    private double searchLStep = 0;
    private double searchTStep = 0;
    private double searchWStep = 0;
    private double homeTvTStep = 0;
    private double homeTvLStep = 0;
    private int homeTvL, homeTvT, searchT, searchH, searchL, searchW;
    private int clickHomeDoctorAdapterPosition = 0;
    int mainTabHeight = 0;
    int mainTabTop = 0;
    PrivateDoctor privateDoctor;
    PromptDialog promptDialog;
    DrugDialog drugDialog;
    private Gson gson = new Gson();

    private ArrayList<HomepageEntity.DataBean.HealthNumberArticleDTOSBean> healthNumberArticleDTOSArrayList;

    /**
     * 首页数据
     */
    private ArrayList<HomepageEntity.DataBean.DoctorListBean> homeDoctorEntities = new ArrayList<>();
    private NewHomeFragmentDataBinding binding;
    private Context context;
    private Activity activity;
    private FragmentManager childFragmentManager;
    private LayoutInflater mInflater;

    private HomeLiveAdapter liveAdapter;
    private List<VisitorLiveEntity.DataBean.ListBean> liveItems = new ArrayList<>();
    private List<ReBuyEntity.DataBean> reBuys = new ArrayList<>();

    private HomeDrugVPAdapter drugVPAdapter;
    private List<NewHomeDrugListFragment> drugFragments = new ArrayList<>();
    private HomeDoctorAdapter homeDoctorAdapter;

    public BuyDrugAdapter buyDrugAdapter;

    public HomeViewModel(@NonNull Application application) {
        super(application);
    }

    private List<HomepageEntity.DataBean.HomeAdBannerBean> bannerBeans = new ArrayList<>();

    List<LiveTabBean.DataBean.LiveCategoryBean> live_category;

    private List<HomeCommodityGroupListEntity.Commodity> commodityListEntities = new ArrayList<>();

    PrivateDoctorEntity.DataBean privateBean;

    ArrayList<String> scheduleStrings = new ArrayList<>();

    ArrayList<AgencyMatterStatiesticsListBean.DataBean.AgencyMatterStatisticsListBean> agencyMatterStatiesticsListBeans = new ArrayList<>();
    /**
     * 临时存储变量
     */
    public static boolean isDrugsTlFixed = false;
    private String price = "";
    private String commodityType = "drug";
    private int queryDoctorPage = 1;
    private String queryDoctorId = "";
    private String chargeOrderCount = "0";
    private String platformActivitiesId = "", platformActivitiesSubjectId = "";
    DoctorHealthAdapter doctorHealthAdapter;
    DoctorHealthAdapter.OnPagerClickListener onPagerClickListener;

    @Override
    public void createRepository() {
        super.createRepository();
        repository = new HomeModel();
    }

    @Override
    protected void onCleared() {
        super.onCleared();
    }

    public void initModel(NewHomeFragmentDataBinding binding, Context context, Activity activity, FragmentManager childFragmentManager) {
        this.binding = binding;
        this.context = context;
        this.activity = activity;
        this.childFragmentManager = childFragmentManager;
    }

    public void initView() {
        binding.liveTab.setTabLayoutTextSize_select(R.style.TabLayoutTextSize_select1, R.style.TabLayoutTextSize_unselect1);
        mInflater = LayoutInflater.from(context);
        binding.tlDrug.setupWithViewPager(binding.vpDrug);
        binding.tlDrugFixed.setupWithViewPager(binding.vpDrug);
        Glide.with(context).load("https://cdn.yilijk.com/images/vbp/patientimg/ext/audit_icon1.png").into(binding.toScanQrcodeImg);

        liveAdapter = new HomeLiveAdapter(context, liveItems);
        binding.rvLive.setLayoutManager(new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false));
        binding.rvLive.setAdapter(liveAdapter);

        drugVPAdapter = new HomeDrugVPAdapter(childFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, drugFragments);
        binding.vpDrug.setAdapter(drugVPAdapter);

        LinearLayoutManager ms = new LinearLayoutManager(context);
        ms.setOrientation(LinearLayoutManager.HORIZONTAL);//
        binding.homeDoctoeRv.setLayoutManager(ms);
        homeDoctorAdapter = new HomeDoctorAdapter(homeDoctorEntities);
        binding.homeDoctoeRv.setAdapter(homeDoctorAdapter);

        buyDrugAdapter = new BuyDrugAdapter(reBuys);
        binding.buydrugList.setLayoutManager(new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false));
        binding.buydrugList.setAdapter(buyDrugAdapter);
        buyDrugAdapter.notifyDataSetChanged();

        privateDoctor = new PrivateDoctor(context);
        drugDialog = new DrugDialog(context);
        promptDialog = new PromptDialog(context);

        healthNumberArticleDTOSArrayList = new ArrayList<>();
        onPagerClickListener = new DoctorHealthAdapter.OnPagerClickListener() {
            @Override
            public void itemClick(View view, int position) {
                ARouter.getInstance()
                        .build(ARouterConstants.Home.DoctorHealthActivity)
                        .withInt("id", healthNumberArticleDTOSArrayList.get(position).getId())
                        .navigation();

            }

            @Override
            public void itemChildClick(View view, int position) {
//                if (view.getId() == R.id.doctor_health_card_do_good) {
//                    LoadingUtils.getLoadingUtils(context).showLoading();
//                    if (healthNumberArticleDTOSArrayList.get(position).getThumbsUp() == 1) {
//                        doThumbsDown(healthNumberArticleDTOSArrayList.get(position).getId(), position);
//                    } else {
//                        doThumbsUp(healthNumberArticleDTOSArrayList.get(position).getId(), position);
//                    }
//                }
            }

            @Override
            public void itemThumbsUp(int thumbs, int position) {
                ALog.e("thumbs ==== 网络请求点赞数 ====="+thumbs+"");
                doThumbsUp(healthNumberArticleDTOSArrayList.get(position).getId(),thumbs,position);
            }
        };
        doctorHealthAdapter = new DoctorHealthAdapter(healthNumberArticleDTOSArrayList, (Activity) context,
                binding.healthDoctorCard.doctorHealthVp,
                binding.healthDoctorCard.doctorHealthVpSign,
                onPagerClickListener).setInfiniteLoop(true);
        binding.healthDoctorCard.doctorHealthVp.setAdapter(doctorHealthAdapter);

        refreshViewFlipper(binding.viewFlipper, null);
        refreshViewFlipper(binding.viewFlipperFixed, null);

    }

    private void refreshViewFlipper(ViewFlipper viewFlipper, List<SecretWordBean.SecretWord> secretWords) {
        viewFlipper.removeAllViews();
        if (secretWords == null || ListUtil.getSize(secretWords) <= 0) {
            if (viewFlipper.isFlipping()) {
                viewFlipper.stopFlipping();
            }
            viewFlipper.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    gotoSearchPage(null, false);
                }
            });
            return;
        }
        viewFlipper.setFlipInterval(3 * 1000);

        viewFlipper.setOutAnimation(
                AnimationUtils.loadAnimation(context, R.anim.filpper_out)
        );
        viewFlipper.setInAnimation(
                AnimationUtils.loadAnimation(context, R.anim.flipper_in)
        );

        for (SecretWordBean.SecretWord secretWord : secretWords) {
            if (secretWord == null || TextUtils.isEmpty(secretWord.getKeyword())) {
                continue;
            }
            TextView view = (TextView) LayoutInflater.from(context).inflate(R.layout.layout_flipper_search, viewFlipper, false);
            view.setText(secretWord.getKeyword());
            view.setTag(R.id.secret_word_id, gson.toJson(secretWord));
            viewFlipper.addView(view);
        }

        if (!viewFlipper.isFlipping()) {
            viewFlipper.startFlipping();
        }
        viewFlipper.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (viewFlipper == null) {
                    return;
                }
                gotoSearchPage(viewFlipper, false);
            }
        });
    }

    private boolean isBlock = false;

    public void initListener() {

        ClickUtils.setFastOnClickListener(binding.layoutSchedule.scheduleClose,v -> {
            binding.layoutSchedule.scheduleRl.setVisibility(View.GONE);
        });

        binding.layoutSchedule.scheduleNoticeview.setOnItemClickListener(new NoticeView.OnItemClickListener() {
            @Override
            public void onItemClick(TextView view, int position) {
                Bundle bundle = new Bundle();
                bundle.putInt("agencyMatterType",agencyMatterStatiesticsListBeans.get(binding.layoutSchedule.scheduleNoticeview.getCurrentNotice()).getAgencyMatterType());
                bundle.putString("agencyMatterStatiesticsListBeans",new Gson().toJson(agencyMatterStatiesticsListBeans));
                HomeUtils.push(context, KitArouterConstants.HOME_DOCTORBUNDLE, KitArouterConstants.Home.Schedule,bundle);
            }
        });
        ClickUtils.setFastOnClickListener(binding.layoutSchedule.scheduleToAll,v -> {
            Bundle bundle = new Bundle();
            bundle.putInt("agencyMatterType",1);
            bundle.putString("agencyMatterStatiesticsListBeans",new Gson().toJson(agencyMatterStatiesticsListBeans));
            HomeUtils.push(context, KitArouterConstants.HOME_DOCTORBUNDLE, KitArouterConstants.Home.Schedule,bundle);
        });

        binding.healthDoctorCard.healthMore.setOnClickListener(v -> {
            HomeUtils.push(context, KitArouterConstants.HOME_DOCTORBUNDLE, "DoctorHealth");
        });

        binding.tlDrug.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                ClickUtils.sendEvent(click_drugstab, context, "药品tab切换点击");
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        ClickUtils.setFastOnClickListener(binding.rlMsgA, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ClickUtils.sendEvent(click_systemmessage, context, "消息点击");
                HomeUtils.push(context, KitArouterConstants.IM_DOCTORBUNDLE, KitArouterConstants.Message.MessageContent);
            }
        });
        ClickUtils.setFastOnClickListener(binding.rlMsg, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ClickUtils.sendEvent(click_systemmessage, context, "消息点击");
                HomeUtils.push(context, KitArouterConstants.IM_DOCTORBUNDLE, KitArouterConstants.Message.MessageContent);
            }
        });

        binding.viewAutoscroll.autoScrollVp.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                binding.viewAutoscroll.autoScrollVp.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                ViewGroup.LayoutParams layoutParams = binding.viewAutoscroll.autoScrollVp.getLayoutParams();
                layoutParams.width = ScreenUtils.getScreenWidth() - ScreenUtils.dip2px(context, 20);
                layoutParams.height = (int) (layoutParams.width * 100 / 355);
                binding.viewAutoscroll.autoScrollVp.setLayoutParams(layoutParams);
            }
        });

        ClickUtils.setFastOnClickListener(binding.ivToTop, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (context == null) {
                    return;
                }
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    return;
                }
                binding.nestedScrollview.scrollTo(0, 0);
                if (binding.tlDrugFixed.getVisibility() != View.INVISIBLE) {
                    binding.tlDrugFixed.setVisibility(View.INVISIBLE);
                    isDrugsTlFixed = false;
                    binding.nestedScrollview.setNeedScroll(true);
                    HomeObservable.getInstance().homeDrugListScrollToTop();
                }

                if (binding.ivToTop.getVisibility() != View.GONE) {
                    binding.ivToTop.setVisibility(View.GONE);
                }
            }
        });

        ClickUtils.setAdapterItemFastOnClickListener(buyDrugAdapter, new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ClickUtils.sendEvent(click_rebuylist, context, "复诊购药列表点击");
                ReBuyEntity.DataBean dataBean = reBuys.get(position);
                //判断是否存在doctorId  若存在 该药品归属对应的医生 跳转下单  若无 该药品为非历史购买  请求接口查询是否存在多个医生同时售卖
                price = dataBean.getPrice() + "";
                commodityType = dataBean.getCommodityType();
                if (!TextUtils.isEmpty(dataBean.getDoctorId())) { //确认下单页面
                    //下单页面
                    getCofirmId(price, dataBean.getDoctorId() + "", queryDoctorId = dataBean.getCommodityId(), commodityType);
                } else {
                    if (TextUtils.isEmpty(dataBean.getCommodityId())) {
                        return;
                    }
                    //请求接口查询对应售卖医生
                    getQueryDrugToDoctor(queryDoctorPage, queryDoctorId = dataBean.getCommodityId(), dataBean.getCommodityType());
                }
            }
        });

        //复诊====选择私人医生点击回调处理
        privateDoctor.setShowCallBack(new PrivateDoctor.ShowCallBack() {
            @Override
            public void getRefresh(SmartRefreshLayout smartRefreshLayout) {
                if (privateBean.isHasNextPage()) {
                    queryDoctorPage++;
                    getQueryDrugToDoctor(queryDoctorPage, queryDoctorId, commodityType);
                }
                smartRefreshLayout.finishLoadMore();
            }

            @Override
            public void click(String doctorId) {
                getCofirmId(price, doctorId, queryDoctorId, commodityType);
            }

            @Override
            public void onDismiss() {
                queryDoctorPage = 1;
            }
        });
        //复诊====更多
        ClickUtils.setFastOnClickListener(binding.buydrugMore, v -> {
            //点击更多弹出复购用药的药品 仅展示药品信息
            ClickUtils.sendEvent(click_rebuymore, context, "复诊购药更多点击");
//            HttpUtils.get(AllStringConstants.)
            getRepository().getReBuyDrugData(new HttpCallBack<ReBuyEntity>() {
                @Override
                public void onSuccess(ReBuyEntity reBuyEntity, int i) {
                    drugDialog.show();
                    drugDialog.setData(reBuyEntity.getData());
                }

                @Override
                public void onFailure(String s, int i) {

                }
            });
        });
        //复诊====药品列表弹窗点击回调处理
        drugDialog.setDrugDialogCall(new DrugDialog.DrugDialogCall() {
            @Override
            public void click(String p, String doctorId, String commodityId, String type) {
                price = p;
                if (!TextUtils.isEmpty(type)) {
                    getCofirmId(price, doctorId, commodityId, type);
                } else {
                    getCofirmId(price, doctorId, commodityId, commodityType);
                }
            }

            @Override
            public void click(String p, String commodityId, String type) {
                commodityType = type;
                price = p;
                getQueryDrugToDoctor(queryDoctorPage, queryDoctorId = commodityId, type);
            }
        });

        ClickUtils.setFastOnClickListener(binding.liveMore, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_morelive, context, "更多直播点击");
                HomeUtils.toJumeLiveList();
            }
        });
        /**
         * 悬浮球点击事件处理
         */
        ClickUtils.setFastOnClickListener(binding.suspendedBallView, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_ball, context, "悬浮球点击");
                binding.suspendedBallView.show();
            }
        });

        binding.liveTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_liveTab, context, "直播tab点击" + tab.getPosition());
                getLiveList(live_category.get(tab.getPosition()).getId() + "");
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        //随访点击、
        ClickUtils.setFastOnClickListener(binding.homeFollowupLayout, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_followUp, context, "我的随访点击");
                if (context == null) {
                    return;
                }
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    LoginThenRouterUtils.RouterBean bean = new LoginThenRouterUtils.RouterBean(
                            TYPE_FOLLOW, KitArouterConstants.HOME_DOCTORBUNDLE, KitArouterConstants.Home.FollowUp, null
                    );
                    LoginThenRouterUtils.getInstance().setBean(bean);
                    return;
                }
                HomeUtils.push(context, KitArouterConstants.HOME_DOCTORBUNDLE, KitArouterConstants.Home.FollowUp);
            }
        });
        ClickUtils.setFastOnClickListener(binding.homeFollowupLayoutRe, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_followUp, context, "我的随访点击");
                if (context == null) {
                    return;
                }
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    LoginThenRouterUtils.RouterBean bean = new LoginThenRouterUtils.RouterBean(
                            TYPE_FOLLOW, KitArouterConstants.HOME_DOCTORBUNDLE, KitArouterConstants.Home.FollowUp, null
                    );
                    LoginThenRouterUtils.getInstance().setBean(bean);
                    return;
                }
                HomeUtils.push(context, KitArouterConstants.HOME_DOCTORBUNDLE, KitArouterConstants.Home.FollowUp);
            }
        });
        ClickUtils.setFastOnClickListener(binding.llScan, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_scanDoctor, context, "扫描医生绑定点击");
                if (context == null) {
                    return;
                }
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    return;
                }
                if (!DevicesUtils.isPermissionExsit((Activity) context, Manifest.permission.CAMERA)) {
                    DevicesUtils.requestPremission((Activity) context, Manifest.permission.CAMERA);
                } else {
                    Intent intent = new Intent(context, QrCodeActivity.class);
                    ((Activity) context).startActivityForResult(intent, 10002);
                }
            }
        });
        //扫描二维码
        ClickUtils.setFastOnClickListener(binding.toScanQrcode, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_scan, context, "扫一扫点击");
                if (context == null) {
                    return;
                }
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    return;
                }
                if (!DevicesUtils.isPermissionExsit((Activity) context, Manifest.permission.CAMERA)) {
                    DevicesUtils.requestPremission((Activity) context, Manifest.permission.CAMERA);
                } else {
                    Intent intent = new Intent(context, QrCodeActivity.class);
                    ((Activity) context).startActivityForResult(intent, 10002);
                }
            }
        });

        ClickUtils.setFastOnClickListener(binding.tvSearchBtn, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_search, context, "搜索点击");
                if (context == null) {
                    return;
                }
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    return;
                }
                gotoSearchPage(binding.viewFlipper, true);
            }
        });

        ClickUtils.setFastOnClickListener(binding.tvSearchBtnFixed, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_search, context, "搜索点击");
                if (context == null) {
                    return;
                }
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    return;
                }
                gotoSearchPage(binding.viewFlipperFixed, true);
            }
        });

        ClickUtils.setFastOnClickListener(binding.qualify.llQualify, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_qualify, context, "医疗资格点击");
                if (context == null) {
                    return;
                }
                RequestParams jsonObject = new RequestParams();
                jsonObject.put("faqId", FAQ_QUA);
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    LoginThenRouterUtils.RouterBean bean = new LoginThenRouterUtils.RouterBean(
                            TYPE_QUALIFY, "", "", jsonObject
                    );
                    LoginThenRouterUtils.getInstance().setBean(bean);
                    return;
                }

                if (isBlock) {
                    return;
                }
                isBlock = true;
                LoadingUtils.getLoadingUtils(context).showLoading();
                HttpUtils.get(getQuality, jsonObject, new HttpCallBack<FaqEntity>() {
                    @Override
                    public void onSuccess(FaqEntity entity, int i) {
                        isBlock = false;
                        if (entity != null && entity.isResult()) {
                            ARouter.getInstance().build(ARouterConstants.MineWebviewActivity)
                                    .withString("title", entity.getData().getTitle())
                                    .withString("url", entity.getData().getContent())
                                    .withBoolean("ishtml", true)
                                    .navigation();
                        }
                        LoadingUtils.getLoadingUtils(context).dismissLoading();
                    }

                    @Override
                    public void onFailure(String s, int i) {
                        isBlock = false;
                        LoadingUtils.getLoadingUtils(context).dismissLoading();
                    }
                });
            }
        });

        binding.vpDrug.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                ALog.e("oakkk", "on page selected:" + position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });


        // 然后设置进去。
        binding.nestedScrollview.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

                ALog.e("oakkk", "home scroll Y: " + scrollY + " " + (binding.tlDrugFixed.getVisibility() == View.VISIBLE));

                HomeBackApi homeBackApi = (HomeBackApi) ARouter.getInstance().build(ARouterConstants.HomeModuleImpl).navigation();
                if (activity != null) {
                    homeBackApi.hideImLayout(activity);
                }

                refreshScrollAnimationData();

                if (binding.llSearch.getVisibility() == View.GONE) {
                    if (binding.flFakeTitle.getVisibility() != View.VISIBLE) {
                        binding.flFakeTitle.setVisibility(View.VISIBLE);
                    }
                    return;
                } else {
                    if (binding.flFakeTitle.getVisibility() != View.GONE) {
                        binding.flFakeTitle.setVisibility(View.GONE);
                    }
                }

                if (scrollY > changeScrollH) {
                    //头部搜索框固定
                    if (binding.llTopFixed.getVisibility() != View.VISIBLE) {
                        binding.llTopFixed.setVisibility(View.VISIBLE);
                    }
                    if (binding.flHeaderTop.getVisibility() != View.INVISIBLE) {
                        binding.flHeaderTop.setVisibility(View.INVISIBLE);
                    }
                    if (scrollY > (binding.tlDrug.getTop() - binding.llTopFixed.getTop() - binding.llTopFixed.getMeasuredHeight())) {
                        if (binding.tlDrugFixed.getVisibility() != View.VISIBLE) {
                            binding.tlDrugFixed.setVisibility(View.VISIBLE);
                            binding.nestedScrollview.setNeedScroll(false);
                            isDrugsTlFixed = true;
                        }
                        if (binding.ivToTop.getVisibility() != View.VISIBLE) {
                            binding.ivToTop.setVisibility(View.VISIBLE);
                        }
                    } else {
                        if (binding.tlDrugFixed.getVisibility() != View.INVISIBLE) {
                            binding.tlDrugFixed.setVisibility(View.INVISIBLE);
                            isDrugsTlFixed = false;
                            binding.nestedScrollview.setNeedScroll(true);
                            HomeObservable.getInstance().homeDrugListScrollToTop();
                        }

                        if (binding.ivToTop.getVisibility() != View.GONE) {
                            binding.ivToTop.setVisibility(View.GONE);
                        }
                    }

                } else if (scrollY > 0) {

                    //头部搜索框变动
                    if (binding.llTopFixed.getVisibility() != View.INVISIBLE) {
                        binding.llTopFixed.setVisibility(View.INVISIBLE);
                    }
                    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) binding.tvHome.getLayoutParams();
                    layoutParams.leftMargin = (int) (homeTvL + homeTvLStep * scrollY);
                    layoutParams.topMargin = (int) (homeTvT + homeTvTStep * scrollY + scrollY);
                    binding.tvHome.setLayoutParams(layoutParams);
                    FrameLayout.LayoutParams currentSearchLp = (FrameLayout.LayoutParams) binding.llSearch.getLayoutParams();
                    currentSearchLp.height = (int) (searchH + searchHStep * scrollY);
                    currentSearchLp.width = (int) (searchW + searchWStep * scrollY);
                    currentSearchLp.topMargin = (int) (searchT + scrollY + searchTStep * scrollY);
                    currentSearchLp.leftMargin = (int) (searchL + searchLStep * scrollY);
                    binding.llSearch.setLayoutParams(currentSearchLp);

                    if (binding.flHeaderTop.getVisibility() != View.VISIBLE) {
                        binding.flHeaderTop.setVisibility(View.VISIBLE);
                    }
                } else {
                    //头部搜索狂初始化
                    if (binding.llTopFixed.getVisibility() != View.INVISIBLE) {
                        binding.llTopFixed.setVisibility(View.INVISIBLE);
                    }
                    FrameLayout.LayoutParams layoutParam = (FrameLayout.LayoutParams) binding.tvHome.getLayoutParams();
                    layoutParam.leftMargin = homeTvL;
                    layoutParam.topMargin = homeTvT;
                    binding.tvHome.setLayoutParams(layoutParam);

                    FrameLayout.LayoutParams layoutParam1 = (FrameLayout.LayoutParams) binding.llSearch.getLayoutParams();
                    layoutParam1.height = searchH;
                    layoutParam1.width = searchW;
                    layoutParam1.topMargin = searchT;
                    layoutParam1.leftMargin = searchL;
                    binding.llSearch.setLayoutParams(layoutParam1);
                    if (binding.flHeaderTop.getVisibility() != View.VISIBLE) {
                        binding.flHeaderTop.setVisibility(View.VISIBLE);
                    }
                }
            }
        });
        //医生卡子控件点击
        homeDoctorAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                clickHomeDoctorAdapterPosition = position;
                if (view.getId() == R.id.cusult_doctor) {
                    //TODO 埋点
                    JSONObject jsonObject = new JSONObject();
                    if (!homeDoctorEntities.get(position).isChargeEnable()) {
//                        ToastUtils.showShort("医生暂未开通问诊服务，已为您通知医生，请耐心等");
                        if (homeDoctorEntities.get(position).isNotifyOpenCharge()){
                            ToastUtils.showShort("医生暂未开通问诊服务，已为您通知医生，请耐心等待");
                        }else{
                            getNotify(homeDoctorEntities.get(position).getDoctorId(),position);
//                            ToastUtils.showShort("邀请成功，已为您提醒医生，敬请等待！");
                        }
                        try {
                            jsonObject.put("name", "通知开通问诊服务");
                            jsonObject.put("doctorId", homeDoctorEntities.get(position).getDoctorId() + "");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        ClickUtils.sendEvent("first_page_lead_doctor_upgrade", context, false, jsonObject);
                        return;
                    }
                    try {
                        jsonObject.put("name", "咨询" + homeDoctorEntities.get(position).getDoctorId() + "医生点击");
                        jsonObject.put("doctorId", homeDoctorEntities.get(position).getDoctorId());
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    ClickUtils.sendEvent(ClickApi.Home.click_cusult, context, false, jsonObject);
                    //咨询医生
//                    Bundle bundle = new Bundle();
//                    bundle.putString("doctorId", homeDoctorEntities.get(position).getDoctorId());
//                    bundle.putInt("selectIndex", 1);
//                    HomeUtils.push(context, KitArouterConstants.IM_DOCTORBUNDLE, KitArouterConstants.Message.DoctorStudio, bundle);
                    HomeUtils.getHomeUtil(context)
                            .jumpNativePage_DoctorStudio(Long.parseLong(homeDoctorEntities.get(position).getDoctorId()),null,1,1);
                } else if (view.getId() == R.id.fast_track) {
                    //TODO 埋点
                    ClickUtils.sendEvent(ClickApi.Home.click_fastTrack, context, "快速购药" + homeDoctorEntities.get(position).getDoctorId() + "点击");
                    if (!homeDoctorEntities.get(position).isHasETP()) {
                        return;
                    }
                    //快速购药
                    Bundle bundle = new Bundle();
                    bundle.putString("doctorId", homeDoctorEntities.get(position).getDoctorId());
                    HomeUtils.push(context, KitArouterConstants.CART_DOCTORBUNDLE, KitArouterConstants.Cart.Drug, bundle);
                } else if (view.getId() == R.id.card_more) {
                    View outerView = LayoutInflater.from(context).inflate(homeDoctorEntities.size() != 1 ? R.layout.pop_hide : R.layout.pop_look_more, null);
                    PopupWindow popupWindow = new PopupWindow(outerView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    if (homeDoctorEntities.size() != 1) {
                        outerView.findViewById(R.id.pop_hide_img).setOnClickListener(v -> {
                            //隐藏
                            popupWindow.dismiss();
                            getRepository().hiddenDoctor(homeDoctorEntities.get(position).getDoctorId(), new HttpCallBack<String>() {
                                @Override
                                public void onSuccess(String s, int i) {
                                    getHomePageBannerData();
                                }

                                @Override
                                public void onFailure(String s, int i) {

                                }
                            });
                        });
                    } else {
                        outerView.findViewById(R.id.pop_look_more_img).setOnClickListener(v -> {
                            //查看更多
                            popupWindow.dismiss();
                            ARouter.getInstance()
                                    .build(ARouterConstants.Mine.MyDoctorActivity)
                                    .navigation();
                        });
                    }

                    popupWindow.setFocusable(true);
                    popupWindow.setOutsideTouchable(true);
                    popupWindow.setOnDismissListener(() -> {
//                        CommonUtils.setBackgroundAlpha((Activity) context,1.0f);
                    });

//                    CommonUtils.setBackgroundAlpha((Activity) context,0.7f);
                    popupWindow.showAsDropDown(view, -(view.getWidth() / 2), -(view.getHeight() / 3), Gravity.BOTTOM);
                }
            }
        });
        //医生卡点击
        homeDoctorAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_doctorCard, context, "医生卡片" + position + "点击");
                clickHomeDoctorAdapterPosition = position;
                //咨询医生
                HomeUtils.getHomeUtil(context)
                        .jumpNativePage_DoctorStudio(Long.parseLong(homeDoctorEntities.get(position).getDoctorId()),null,0,0);
            }
        });
        //首页订单跳转
        ClickUtils.setFastOnClickListener(binding.homeOrderLayout, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_myOrder, context, "我的订单点击");
                if (context == null) {
                    return;
                }
                //咨询医生
                Bundle bundle = new Bundle();
                bundle.putString("doctorId", "11111");
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    LoginThenRouterUtils.RouterBean bean = new LoginThenRouterUtils.RouterBean(
                            TYPE_ORDER, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.MyOrder, bundle
                    );
                    LoginThenRouterUtils.getInstance().setBean(bean);
                    return;
                }
                HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.MyOrder, bundle);
//                Bundle bundle = new Bundle();
//                bundle.putString("flag", "");
//                HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.MyOrder, bundle);
            }
        });
        ClickUtils.setFastOnClickListener(binding.homeOrderLayoutRe, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_myOrder, context, "我的订单点击");
                if (context == null) {
                    return;
                }
                //咨询医生
                Bundle bundle = new Bundle();
                bundle.putString("doctorId", "11111");
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    LoginThenRouterUtils.RouterBean bean = new LoginThenRouterUtils.RouterBean(
                            TYPE_ORDER, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.MyOrder, bundle
                    );
                    LoginThenRouterUtils.getInstance().setBean(bean);
                    return;
                }
                HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.MyOrder, bundle);
//                Bundle bundle = new Bundle();
//                bundle.putString("flag", "");
//                HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.MyOrder, bundle);
            }
        });
        //首页问诊跳转
        ClickUtils.setFastOnClickListener(binding.homeAskLayout, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_myAsk, context, "我的问诊点击");
                if (context == null) {
                    return;
                }
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    LoginThenRouterUtils.RouterBean bean = new LoginThenRouterUtils.RouterBean(
                            TYPE_ASK, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.MyConsultation, null
                    );
                    LoginThenRouterUtils.getInstance().setBean(bean);
                    return;
                }
                Bundle bundle = new Bundle();
                bundle.putString("status", "unused");
                HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.MyConsultation, bundle);
            }
        });
        ClickUtils.setFastOnClickListener(binding.homeAskLayoutRe, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_myAsk, context, "我的问诊点击");
                if (context == null) {
                    return;
                }
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    LoginThenRouterUtils.RouterBean bean = new LoginThenRouterUtils.RouterBean(
                            TYPE_ASK, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.MyConsultation, null
                    );
                    LoginThenRouterUtils.getInstance().setBean(bean);
                    return;
                }
                Bundle bundle = new Bundle();
                bundle.putString("status", "unused");
                HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.MyConsultation, bundle);
            }
        });
        //心心
        ClickUtils.setFastOnClickListener(binding.homeXxxrDoctorLayout, v -> {
            ClickUtils.sendEvent(ClickApi.Home.click_xinxin, context, "首页心心向荣点击");
            getXxxrUrl();
        }); //心心
        ClickUtils.setFastOnClickListener(binding.homeXxxrDoctorLayoutRe, v -> {
            ClickUtils.sendEvent(ClickApi.Home.click_xinxin, context, "首页心心向荣点击");
            getXxxrUrl();
        });
        //首页医生跳转
        ClickUtils.setFastOnClickListener(binding.homeDoctorLayout, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_myDoctor, context, "我的医生点击");
                if (context == null) {
                    return;
                }
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
//                    LoginThenRouterUtils.RouterBean bean = new LoginThenRouterUtils.RouterBean(
//                            TYPE_DOCTOR, KitArouterConstants.MY_BUNDLE, KitArouterConstants.MyDoctor, null
//                    );
//                    LoginThenRouterUtils.getInstance().setBean(bean);
                    return;
                }
//                HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.MyDoctor);
                HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.ServiceEquityList);
            }
        });
        ClickUtils.setFastOnClickListener(binding.homeDoctorLayoutRe, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_myDoctor, context, "我的医生点击");
                if (context == null) {
                    return;
                }
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
//                    LoginThenRouterUtils.RouterBean bean = new LoginThenRouterUtils.RouterBean(
//                            TYPE_DOCTOR, KitArouterConstants.MY_BUNDLE, KitArouterConstants.MyDoctor, null
//                    );
//                    LoginThenRouterUtils.getInstance().setBean(bean);
                    return;
                }
                Bundle bundle = new Bundle();
                bundle.putString("type", "1");
//                HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.ServiceEquityList,bundle);
                HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.ServiceEquityList, bundle);
            }
        });
        //首页处方跳转
        ClickUtils.setFastOnClickListener(binding.homePrescriptionLayout, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_myPrescription, context, "我的处方点击");
                if (context == null) {
                    return;
                }
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    LoginThenRouterUtils.RouterBean bean = new LoginThenRouterUtils.RouterBean(
                            TYPE_PRESCRIPTION, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.MyPrescription, null
                    );
                    LoginThenRouterUtils.getInstance().setBean(bean);
                    return;
                }
                Bundle bundle = new Bundle();
                bundle.putString("status", "unused");
                HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.MyPrescription, bundle);

            }
        });
        ClickUtils.setFastOnClickListener(binding.homePrescriptionLayoutRe, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_myPrescription, context, "我的处方点击");
                if (context == null) {
                    return;
                }
                String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
                String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
                if (token == null && account_mobile == null) {
                    HomeUtils.push(context, KitArouterConstants.LOGIN_DOCTORBUNDLE, KitArouterConstants.Login.Index);
                    LoginThenRouterUtils.RouterBean bean = new LoginThenRouterUtils.RouterBean(
                            TYPE_PRESCRIPTION, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.MyPrescription, null
                    );
                    LoginThenRouterUtils.getInstance().setBean(bean);
                    return;
                }
                Bundle bundle = new Bundle();
                bundle.putString("status", "unused");
                HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.MyPrescription, bundle);

            }
        });
        ClickUtils.setFastOnClickListener(binding.answerActivity, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 埋点
                ClickUtils.sendEvent(ClickApi.Home.click_myAnswer, context, "答题卡点击");
//                HomeUtils.startAnswer();
                ARouter.getInstance().build(ARouterConstants.HealthAnswerActivity)
                        .withString("platformActivitiesId", platformActivitiesId)
                        .withString("platformActivitiesSubjectId", platformActivitiesSubjectId)
                        .navigation();
            }
        });


    }

    public void initData() {
        /**
         * 悬浮球是否显示
         * SuspendedBallView.HiddenCallBack()
         */
        binding.suspendedBallView.isHiddenSuspendedBallView(1, new SuspendedBallView.HiddenCallBack() {
            @Override
            public void hidden(boolean hidden) {
                if (hidden) {
                    binding.suspendedBallView.setVisibility(View.GONE);
                } else {
                    binding.suspendedBallView.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void setIcon(String iconUrl) {
                if (iconUrl != null) {
                    binding.suspendedBallView.setGifIcon(iconUrl);
                } else {
                    binding.suspendedBallView.setGifIcon(R.drawable.icon_default_square);
                }
            }

            @Override
            public void getUrl(String url) {
                binding.suspendedBallView.setActivityUrl(url);
            }

        });

        binding.qualify.llQualify.setVisibility(View.INVISIBLE);
//        try {
////            getCheckLogin();
////            getPreference();
////            getHomePage();
////            getIsShowText();
//
////            getHomePageBannerData();
////            getHomeCommodityGroupList();
//            if (ProjectConfigure.Open.isOpenLive) {
////                liveLl.setVisibility(View.VISIBLE);
//                getLiveTab();
////                getLiveData();
//            } else {
////                liveLl.setVisibility(View.GONE);
//            }
//
//            getHomePageBannerData();
//            getHomeCommodityGroupList();
//            if (ProjectConfigure.Open.isOpenLive) {
//                getLiveTab();
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }


    }

    private void getQueryDrugToDoctor(int queryDoctorPage, String s, String commodityType) {
        LoadingUtils.getLoadingUtils(context).showLoading();
        getRepository().getQueryDrugToDoctor(queryDoctorPage, s, commodityType, new HttpCallBack<PrivateDoctorEntity>() {
            @Override
            public void onSuccess(PrivateDoctorEntity privateDoctorEntity, int i) {
                if (privateDoctorEntity.isResult()) {
                    privateBean = privateDoctorEntity.getData();
                    if (privateBean != null && privateBean.getMyDoctorVOList() != null) {
                        List<PrivateDoctorEntity.DataBean.MyDoctorVOListBean> list = privateBean.getMyDoctorVOList();
                        //通过接口查询药品所对应的售卖医生 若存在多个医生 弹框提供选择私人医生 若仅有一个医生 默认选中该医生确定下单  若无售卖对应药品医生 则弹窗提示
                        if (privateBean.getMyDoctorVOList().size() > 1) {
                            //选择私人医生弹窗
                            if (!privateDoctor.isShowing()) {
                                privateDoctor.show();
                            }
                            privateDoctor.setData(list);
                        } else if (privateBean.getMyDoctorVOList().size() == 1) {
                            //确认下单页面
                            if (privateDoctor.getDataSize() == 0) {
                                getCofirmId(price, privateBean.getMyDoctorVOList().get(0).getDoctorId() + "", s, commodityType);
                            } else {
                                privateDoctor.setData(list);
                            }
                        } else {
                            //弹窗提示
                            promptDialog.show();
                            promptDialog.setTitle("提示");
                            promptDialog.setContent(context.getResources().getString(R.string.prompt_txt) + context.getResources().getString(R.string.prompt_phone) + "。");
                            promptDialog.setBt("", "确定",
                                    v -> {
                                    }, v -> {
                                        promptDialog.dismiss();
                                    });
                        }
                    }
                }
                LoadingUtils.getLoadingUtils(context).dismissLoading();


            }

            @Override
            public void onFailure(String s, int i) {
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }
        });
    }

    private void getCofirmId(String price, String s, String s1, String commodityType) {
        getRepository().getCofirmId(price, s, s1, commodityType, new HttpCallBack<String>() {
            @Override
            public void onSuccess(String resultMsg, int i) {
                try {
                    JSONObject jsonObject1 = new JSONObject(resultMsg);
                    if (jsonObject1.has("status")) {
                        switch (jsonObject1.getString("status")) {
                            case "200":
                                if (jsonObject1.has("data") && jsonObject1.getString("data") != null) {
                                    JSONObject jsonObject2 = new JSONObject(jsonObject1.getString("data"));
                                    if (jsonObject2.has("confirmId") && jsonObject2.has("dispatch")) {
                                        Bundle bundle = new Bundle();
                                        if ("3".equals(jsonObject2.getString("dispatch"))) {
                                            bundle.putString("confirmId", jsonObject2.getString("confirmId"));
                                            HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.Inquiry1, bundle);
                                        } else {
                                            bundle.putString("id", jsonObject2.getString("confirmId"));
                                            bundle.putString("dispatch", jsonObject2.getString("dispatch"));
                                            HomeUtils.push(context, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.PayChart, bundle);
                                        }
                                    }
                                }
                                break;
                            default:
                                if (jsonObject1.has("message")) {
                                    ToastUtils.showShort(jsonObject1.getString("message"));
                                }
                                break;
                        }
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }

            @Override
            public void onFailure(String s, int i) {
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }
        });
    }

    private void refreshAutoScrollData() {
        if (bannerBeans.size() > 0) {
            binding.homebannerCardview.setVisibility(View.VISIBLE);
        } else {
            binding.homebannerCardview.setVisibility(View.GONE);
        }
        initSign();
        BannerAutoScrollAdapter autoScrollAdapter = new BannerAutoScrollAdapter(context, bannerBeans).setInfiniteLoop(true);
        binding.viewAutoscroll.autoScrollVp.setAdapter(autoScrollAdapter);
        binding.viewAutoscroll.autoScrollVp.setInterval(2000);
//        scrollViewPager.setCurrentItem(Integer.MAX_VALUE / 2);
        binding.viewAutoscroll.autoScrollVp.addOnPageChangeListener(new MyPageChangeListener(bannerBeans, binding.viewAutoscroll.signLl));
        binding.viewAutoscroll.autoScrollVp.startAutoScroll();
    }

    /**
     * 初始化下方小圆点
     */
    private void initSign() {
        binding.viewAutoscroll.signLl.removeAllViews();
        for (int i = 0; i < ListUtil.getSize(bannerBeans); i++) {
            View signView = mInflater.inflate(
                    R.layout.layout_sign, binding.viewAutoscroll.signLl);
            if (i == 0) {
                signView.setSelected(true);
            }
//            signLl.addView(signView);
        }
    }

    public void getLiveTab() {
        getRepository().getLiveTab(new HttpCallBack<LiveTabBean>() {
            @Override
            public void onSuccess(LiveTabBean liveTabBean, int code) {
                if (liveTabBean.getCode().equals("200")) {
                    LiveTabBean.DataBean data = liveTabBean.getData();
                    binding.liveTab.removeAllTabs();
                    live_category = data.getLive_category();
                    if (data.getLive_category().size() == 0) {
                        binding.llLive.setVisibility(View.GONE);
                    } else {
                        binding.llLive.setVisibility(View.VISIBLE);
                        for (LiveTabBean.DataBean.LiveCategoryBean s : liveTabBean.getData().getLive_category()) {
                            TabLayout.Tab tab = binding.liveTab.newTab();
                            tab.setText(s.getName());
                            binding.liveTab.addTab(tab);
                        }
                        ALog.e(binding.liveTab.getChildCount() + "livetabs");
                        for (int i = 0; i < binding.liveTab.getChildCount(); i++) {
                            LinearLayout linearLayout = (LinearLayout) binding.liveTab.getChildAt(i);
                            linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
                            linearLayout.setDividerDrawable(ContextCompat.getDrawable(context, R.drawable.tab_item_r));
                        }
                        getLiveList(liveTabBean.getData().getLive_category().get(0).getId() + "");
                    }
                }
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }

            @Override
            public void onFailure(String s, int i) {
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }
        });
    }

    /**
     * 获取直播数据
     */
    private void getLiveList(String category_id) {
        LoadingUtils.getLoadingUtils(context).showLoading();
        RequestParams jsonObject = new RequestParams();
//        visitor_list_type	0
//        page	1
//        limit	8
        jsonObject.put("category_id", category_id);
        jsonObject.put("api_role", "visitor");

        HttpUtils.get(getLiveVisitorRoom, jsonObject, new HttpCallBack<VisitorLiveEntity>() {
            @Override
            public void onSuccess(VisitorLiveEntity visitorLiveEntity, int i) {
                if (visitorLiveEntity.getCode().equals("200")) {
                    liveItems.clear();
                    liveItems.addAll(visitorLiveEntity.getData().getList());
                    liveAdapter.notifyDataSetChanged();
                    if (visitorLiveEntity.getData().getList().size() > 0) {
                        binding.rvLive.setVisibility(View.VISIBLE);
                        binding.rvLiveNone.setVisibility(View.GONE);
                    } else {
                        binding.rvLive.setVisibility(View.GONE);
                        binding.rvLiveNone.setVisibility(View.VISIBLE);
                    }
                }
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }

            @Override
            public void onFailure(String s, int i) {
                binding.rvLive.setVisibility(View.GONE);
                binding.rvLiveNone.setVisibility(View.VISIBLE);
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }
        });
    }

    public void getHomeCommodityGroupList() {
        LoadingUtils.getLoadingUtils(context).showLoading();
//        commodityListEntities.clear();
        getRepository().getHomeCommodityGroupList(new HttpCallBack<HomeCommodityGroupListEntity>() {
            @Override
            public void onSuccess(HomeCommodityGroupListEntity homeCommodityGroupListEntity, int i) {
                commodityListEntities.clear();
//                if (homeCommodityGroupListEntity.isResult()) {
                if (homeCommodityGroupListEntity.isResult() && homeCommodityGroupListEntity.getData() != null) {
                    commodityListEntities.addAll(homeCommodityGroupListEntity.getData());

                }
                refreshCommodityList();
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }

            @Override
            public void onFailure(String s, int i) {
                refreshCommodityList();
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }
        });
    }

    private void refreshCommodityList() {
        drugFragments.clear();
        for (HomeCommodityGroupListEntity.Commodity commodity : commodityListEntities) {
            drugFragments.add(NewHomeDrugListFragment.getInstance(commodity));
        }
        drugVPAdapter.notifyDataSetChanged();
        if (drugFragments.size() > 0) {
            binding.vpDrug.setCurrentItem(0);
            binding.tlDrugFixed.scrollTo(0, 0);
            binding.tlDrug.scrollTo(0, 0);
            HomeObservable.getInstance().refreshDrugFragmentData();
        }
    }

    public void getHomePageBannerData() {
        LoadingUtils.getLoadingUtils(context).showLoading();
        getPersonalAction();
        getRepository().getHomePageBannerData(new HttpCallBack<HomepageEntity>() {
            @Override
            public void onSuccess(HomepageEntity homepageEntity, int code) {
                if (homepageEntity.isResult()) {
                    binding.homeDoctorLayout.setVisibility(homepageEntity.getData().isHeartToward() ? View.GONE : View.VISIBLE);
                    binding.homeDoctorLayoutRe.setVisibility(homepageEntity.getData().isHeartToward() ? View.GONE : View.VISIBLE);
                    binding.homeXxxrDoctorLayout.setVisibility(homepageEntity.getData().isHeartToward() ? View.VISIBLE : View.GONE);
                    binding.homeXxxrDoctorLayoutRe.setVisibility(homepageEntity.getData().isHeartToward() ? View.VISIBLE : View.GONE);

                    if (homepageEntity.getData().getHealthNumberArticleDTOS() != null && homepageEntity.getData().getHealthNumberArticleDTOS().size() > 0) {
                        binding.healthDoctorCard.healthDoctorCard1.setVisibility(View.VISIBLE);
                        healthNumberArticleDTOSArrayList.clear();
                        healthNumberArticleDTOSArrayList.addAll(homepageEntity.getData().getHealthNumberArticleDTOS());
                        doctorHealthAdapter = new DoctorHealthAdapter(healthNumberArticleDTOSArrayList, (Activity) context,
                                binding.healthDoctorCard.doctorHealthVp,
                                binding.healthDoctorCard.doctorHealthVpSign,
                                onPagerClickListener).setInfiniteLoop(true);
                        binding.healthDoctorCard.doctorHealthVp.setAdapter(doctorHealthAdapter);
                    }

                    if (homepageEntity.getData().getDoctorList() != null && homepageEntity.getData().getDoctorList().size() != 0) {
                        binding.llHomeInfoList.setVisibility(View.GONE);
                        binding.doctorRebuyLl.setVisibility(View.VISIBLE);
                        homeDoctorEntities.clear();
                        int type = 1;
                        if (homepageEntity.getData().getDoctorList().size() > 1) {
                            type = 0;
                        }
                        for (int i = 0; i < homepageEntity.getData().getDoctorList().size(); i++) {
                            HomepageEntity.DataBean.DoctorListBean doctorListBean = homepageEntity.getData().getDoctorList().get(i);
                            doctorListBean.setType(type);
                            homeDoctorEntities.add(doctorListBean);
                        }
                        getReBuyDrugData();
                    }

                    if (homepageEntity.getData() != null && homepageEntity.getData().getAdvertisementBannerList() != null && homepageEntity.getData().getAdvertisementBannerList().size() > 0) {
                        bannerBeans.clear();
                        bannerBeans.addAll(homepageEntity.getData().getAdvertisementBannerList());
                        binding.homebannerCardview.setVisibility(View.VISIBLE);
                    } else {
                        binding.homebannerCardview.setVisibility(View.GONE);
                    }


//                    activityLists.clear();
//                    List<HomepageEntity.DataBean.ActivityListBean> activityList = homepageEntity.getData().getActivityList();
                    //添加活动title
//                    activityLists.clear();
//                    activityListBeans.clear();
//                    for (int i = 0; i < activityList.size(); i++) {
//                        activityLists.add(activityList.get(i).getTitle());
//                        activityListBeans.add(activityList.get(i));
//                    }

                    chargeOrderCount = homepageEntity.getData().getChargeOrderCount();
                }
                refreshAutoScrollData();
                refreshUIchargeOrderCount();
                refreshAnswerData(homepageEntity.getData().getHomePageEverydayAnswerVO());
                refreshHomePage();

                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }

            @Override
            public void onFailure(String s, int i) {
                LoadingUtils.getLoadingUtils(context).dismissLoading();
                ALog.e("okhttp", "get home data failure msg : " + s);
                refreshHomePage();
            }
        });
    }

    private boolean isOpenPersonal = false;

    private void getReBuyDrugData() {
        LoadingUtils.getLoadingUtils(context).showLoading();
        getRepository().getReBuyDrugDataNew(new HttpCallBack<ReBuyEntity>() {
            @Override
            public void onSuccess(ReBuyEntity reBuyEntity, int i) {
                if (reBuyEntity != null && reBuyEntity.isResult() && reBuyEntity.getData() != null && reBuyEntity.getData().size() > 0) {
                    reBuys.clear();
                    reBuys.addAll(reBuyEntity.getData());
                    buyDrugAdapter.notifyDataSetChanged();
                } else {
                    reBuys.clear();
                    buyDrugAdapter.notifyDataSetChanged();
                }
                refreshRebuyStatus();
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }

            @Override
            public void onFailure(String s, int i) {
                reBuys.clear();
                buyDrugAdapter.notifyDataSetChanged();
                refreshRebuyStatus();
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }
        });
    }

    private void getPersonalAction() {
        String account_id = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_id, "");
        if (TextUtils.isEmpty(account_id)) {
            isOpenPersonal = false;
            refreshRebuyStatus();
            return;
        }
        LoadingUtils.getLoadingUtils(context).showLoading();
        getRepository().getUserAction(new HttpCallBack<UserActionEntity>() {
            @Override
            public void onSuccess(UserActionEntity userActionEntity, int i) {
                if ("1".equals(userActionEntity.getData())) {
                    isOpenPersonal = true;
                } else {
                    isOpenPersonal = false;
                }
                refreshRebuyStatus();
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }

            @Override
            public void onFailure(String s, int i) {
                isOpenPersonal = false;
                refreshRebuyStatus();
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }
        });
    }

    private void refreshRebuyStatus() {
        if (ListUtil.getSize(reBuys) > 0 && isOpenPersonal &&  AllStringConstants.isShowReBuy) {
            binding.doctorRebuyList.setVisibility(View.VISIBLE);
        } else {
            binding.doctorRebuyList.setVisibility(View.GONE);
        }
    }

    private void refreshAnswerData(HomepageEntity.DataBean.HomePageEverydayAnswerVO answerVO) {
        if (answerVO != null && !TextUtils.isEmpty(answerVO.getPlatformActivitiesId())) {
            binding.answerActivity.setVisibility(View.VISIBLE);
            platformActivitiesId = answerVO.getPlatformActivitiesId();
            platformActivitiesSubjectId = answerVO.getPlatformActivitiesSubjectId();
            if (!TextUtils.isEmpty(answerVO.getSubjectTitle())) {
                binding.tvAnswerTitle.setText(answerVO.getSubjectTitle());
//                tv_answer_title.setText("禹的儿子 启继承了王位，建立了 第一个奴隶制王朝夏朝（约公元前22世纪至");
//                tv_answer_title.setText("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
                binding.tvAnswerTitle.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        binding.tvAnswerTitle.getViewTreeObserver().removeOnGlobalLayoutListener(this);

//                        Layout layout = tv_answer_title.getLayout();
                        String allTitle = binding.tvAnswerTitle.getText().toString();
                        TextPaint paint = binding.tvAnswerTitle.getPaint();
                        int maxWidth = binding.tvAnswerTitle.getMeasuredWidth();
                        int ivWidth = binding.tvAnswerOption.getMeasuredWidth();
                        StaticLayout staticLayout = new StaticLayout(allTitle, paint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
                        if (staticLayout.getLineCount() <= 0) {
                            return;
                        }
                        float drawableLeft = staticLayout.getLineRight(staticLayout.getLineCount() - 1);
                        //文字大于两行 & 文字等于两行但不足以放下右边View 的情况的处理
                        if (binding.tvAnswerTitle.getLineCount() > 2 || (binding.tvAnswerTitle.getLineCount() == 2 && (maxWidth - staticLayout.getLineRight(1)) < ivWidth)) {
                            StringBuffer stringBuffer = new StringBuffer();
                            for (int i = 0; i < 2; i++) {
                                stringBuffer.append(allTitle.substring(binding.tvAnswerTitle.getLayout().getLineStart(i), binding.tvAnswerTitle.getLayout().getLineEnd(i)));
                            }

                            String text = stringBuffer.substring(0, stringBuffer.length() - 4) + " ...";
                            for (int i = 5; ; i++) {
                                StaticLayout staticLayout1 = new StaticLayout(text, paint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
                                float right = staticLayout1.getLineRight(staticLayout1.getLineCount() - 1);
                                drawableLeft = staticLayout1.getLineRight(staticLayout1.getLineCount() - 1);
                                if ((maxWidth - right) < ivWidth) {
                                    text = stringBuffer.substring(0, stringBuffer.length() - i) + " ...";
                                } else {
                                    break;
                                }
                            }

                            binding.tvAnswerTitle.setText(text);
                        } else if (binding.tvAnswerTitle.getLineCount() == 1 && (maxWidth - staticLayout.getLineRight(0)) < ivWidth) {
                            //文字单行 但不足以放下右边View 的情况的处理
                            binding.tvAnswerTitle.setText(allTitle + "\n");
                            drawableLeft = 0;
                        }
                        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) binding.llAnswerOption.getLayoutParams();
                        layoutParams.leftMargin = (int) (drawableLeft + 1);
                        binding.llAnswerOption.setLayoutParams(layoutParams);

                    }
                });
            }
            //已答题
            if (!TextUtils.isEmpty(answerVO.getFilledOption())) {
                binding.llCheckAnswer.setVisibility(View.VISIBLE);
                binding.llGotoAnswer.setVisibility(View.GONE);
                binding.tvAnswerOption.setVisibility(View.VISIBLE);
                binding.tvAnswerOption.setImageResource(answerVO.isAnswerOption() ? R.drawable.icon_answer_true : R.drawable.icon_answer_fake);

                binding.flSubjectCommentary.setVisibility(View.VISIBLE);
                binding.tvSubjectCommentary.setText(String.format(context.getString(R.string.space_start_2half), answerVO.getSubjectCommentary()));
                binding.llAnswerRateTxt.setVisibility(View.GONE);
                binding.llAnswerRate.setVisibility(View.GONE);
            } else {
                binding.llCheckAnswer.setVisibility(View.GONE);
                binding.llGotoAnswer.setVisibility(View.VISIBLE);
                binding.flSubjectCommentary.setVisibility(View.GONE);
                binding.llAnswerRate.setVisibility(View.VISIBLE);
                binding.llAnswerRateTxt.setVisibility(View.VISIBLE);


                binding.ttvCorrectRate.setNoTrapezoid(false);
                binding.ttvCorrectRate.setBackgroundResource(R.drawable.bg_left_line_no_gradient);
                binding.ttvErrorRate.setNoTrapezoid(false);
                binding.ttvErrorRate.setBackgroundResource(R.drawable.bg_right_line_no_gradient);
                binding.ttvCorrectRate.setText(answerVO.getCorrectRate() + "%");
                binding.ttvErrorRate.setText(answerVO.getErrorRate() + "%");
                if (answerVO.getErrorRate() == 0) {
                    binding.ttvErrorRate.setVisibility(View.GONE);
                    LinearLayout.LayoutParams correctParams = (LinearLayout.LayoutParams) binding.ttvCorrectRate.getLayoutParams();
                    correctParams.weight = 1;
                    correctParams.rightMargin = 0;
                    binding.ttvCorrectRate.setLayoutParams(correctParams);
                    binding.ttvCorrectRate.setText("100%");
                    binding.ttvCorrectRate.setNoTrapezoid(true);
                    binding.ttvCorrectRate.setBackgroundResource(R.drawable.bg_left_line_no_gradient_corner);
                } else if (answerVO.getCorrectRate() == 0) {
                    LinearLayout.LayoutParams errorParams = (LinearLayout.LayoutParams) binding.ttvErrorRate.getLayoutParams();
                    errorParams.weight = 1;
                    errorParams.leftMargin = 0;
                    binding.ttvErrorRate.setLayoutParams(errorParams);
                    binding.ttvErrorRate.setText("100%");
                    binding.ttvErrorRate.setNoTrapezoid(true);
                    binding.ttvErrorRate.setBackgroundResource(R.drawable.bg_right_line_no_gradient_corner);
                    binding.ttvCorrectRate.setVisibility(View.GONE);
                } else if (answerVO.getErrorRate() > 0 && answerVO.getErrorRate() < 13) {
                    LinearLayout.LayoutParams errorParams = (LinearLayout.LayoutParams) binding.ttvErrorRate.getLayoutParams();
                    errorParams.weight = 13;
                    errorParams.leftMargin = -7;
                    binding.ttvErrorRate.setLayoutParams(errorParams);
                    LinearLayout.LayoutParams correctParams = (LinearLayout.LayoutParams) binding.ttvCorrectRate.getLayoutParams();
                    correctParams.weight = 87;
                    correctParams.rightMargin = -7;
                    binding.ttvCorrectRate.setLayoutParams(correctParams);
                } else if (answerVO.getCorrectRate() > 0 && answerVO.getCorrectRate() < 13) {
                    LinearLayout.LayoutParams errorParams = (LinearLayout.LayoutParams) binding.ttvErrorRate.getLayoutParams();
                    errorParams.weight = 87;
                    errorParams.leftMargin = -7;
                    binding.ttvErrorRate.setLayoutParams(errorParams);
                    LinearLayout.LayoutParams correctParams = (LinearLayout.LayoutParams) binding.ttvCorrectRate.getLayoutParams();
                    correctParams.weight = 13;
                    correctParams.rightMargin = -7;
                    binding.ttvCorrectRate.setLayoutParams(correctParams);
                } else {
                    LinearLayout.LayoutParams errorParams = (LinearLayout.LayoutParams) binding.ttvErrorRate.getLayoutParams();
                    errorParams.weight = answerVO.getErrorRate();
                    errorParams.leftMargin = -7;
                    binding.ttvErrorRate.setLayoutParams(errorParams);
                    LinearLayout.LayoutParams correctParams = (LinearLayout.LayoutParams) binding.ttvCorrectRate.getLayoutParams();
                    correctParams.weight = answerVO.getCorrectRate();
                    correctParams.rightMargin = -7;
                    binding.ttvCorrectRate.setLayoutParams(correctParams);
                }

                binding.tvAnswerOption.setVisibility(View.GONE);
            }
        } else {
            binding.answerActivity.setVisibility(View.GONE);
        }
    }


    private void gotoSearchPage(ViewFlipper viewFlipper, boolean isSearch) {
        String keyWord = "";
        String searchId = "";
        if (viewFlipper != null && viewFlipper.getCurrentView() != null && viewFlipper.getCurrentView().getTag(R.id.secret_word_id) != null) {
            try {
                SecretWordBean.SecretWord secretWord = gson.fromJson((String) viewFlipper.getCurrentView().getTag(R.id.secret_word_id), SecretWordBean.SecretWord.class);
                keyWord = secretWord.getKeyword();
                searchId = secretWord.getId();
            } catch (Throwable throwable) {

            }
        }
        Bundle bundle = new Bundle();
        if (!TextUtils.isEmpty(keyWord)) {
            bundle.putString("searchKey", keyWord);
        }
        if (!TextUtils.isEmpty(searchId)) {
            bundle.putString("searchId", searchId);
        }
        bundle.putBoolean("isSearch", isSearch);
        HomeUtils.push(context,
                KitArouterConstants.CART_DOCTORBUNDLE,
                KitArouterConstants.Cart.HomeSearch,
                bundle);
    }

    private void refreshScrollAnimationData() {
        if (mainTabTop == 0) {
            View view = HomeUtils.getMainTabLayoutView((Activity) context);
            if (view != null) {
                mainTabHeight = view.getMeasuredHeight();
                mainTabTop = view.getTop();
            }
        }
        if (homeTvT <= 0) {

            homeTvT = ((FrameLayout.LayoutParams) binding.tvHome.getLayoutParams()).topMargin;
            homeTvL = ((FrameLayout.LayoutParams) binding.tvHome.getLayoutParams()).leftMargin;
            searchH = binding.llSearch.getMeasuredHeight();
            searchT = ((FrameLayout.LayoutParams) binding.llSearch.getLayoutParams()).topMargin;
            searchL = binding.llSearch.getLeft();
            searchW = binding.llSearch.getMeasuredWidth();


            homeTvLStep = 1.0 * (binding.tvHomeFixed.getLeft() - binding.tvHome.getLeft()) / changeScrollH;
            homeTvTStep = 1.0 * (binding.tvHomeFixed.getTop() - binding.tvHome.getTop()) / changeScrollH;
            searchHStep = 1.0 * (binding.llSearchFixed.getMeasuredHeight() - searchH) / changeScrollH;
            searchTStep = 1.0 * (binding.llSearchFixed.getTop() - binding.llSearch.getTop()) / changeScrollH;
            searchWStep = 1.0 * (binding.llSearchFixed.getMeasuredWidth() - searchW) / changeScrollH;
            searchLStep = 1.0 * (binding.llSearchFixed.getLeft() - searchL) / changeScrollH;


            if (binding.vpDrug.getVisibility() == View.VISIBLE && mainTabTop > 0) {
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) binding.vpDrug.getLayoutParams();
                layoutParams.height = mainTabTop - binding.tlDrugFixed.getTop() - binding.tlDrugFixed.getMeasuredHeight() + 1;
                binding.vpDrug.setLayoutParams(layoutParams);
            }
        }
    }

    private void refreshHomePage() {
//        noticeView.setNoticeList(activityLists);
        ALog.e("oakkk", "refresh home page: " + homeDoctorEntities.size());
        if (homeDoctorEntities.size() != 0) {
//            toScanQrcode.setVisibility(View.GONE);
            binding.doctorTitle.doctorCardList.setVisibility(View.VISIBLE);
            binding.vpDrug.setVisibility(View.VISIBLE);
            binding.homeDoctoeRv.setVisibility(View.VISIBLE);
            binding.llSearch.setVisibility(View.VISIBLE);
            binding.llScan.setVisibility(View.GONE);
            binding.tlDrug.setVisibility(View.VISIBLE);
            binding.llHomeInfoList.setBackgroundResource(R.drawable.bg_white);

            if (mainTabTop > 0) {
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) binding.vpDrug.getLayoutParams();
                layoutParams.height = mainTabTop - binding.tlDrugFixed.getTop() - binding.tlDrugFixed.getMeasuredHeight() + 1;
                binding.vpDrug.setLayoutParams(layoutParams);
            }

            LinearLayout.LayoutParams qualifyFl = (LinearLayout.LayoutParams) binding.qualify.llQualify.getLayoutParams();
            qualifyFl.topMargin = ScreenUtils.dip2px(context, 142);
            binding.qualify.llQualify.setLayoutParams(qualifyFl);

            refreshScrollAnimationData();
        } else {

//            toScanQrcode.setVisibility(View.GONE);
            binding.doctorTitle.doctorCardList.setVisibility(View.GONE);
            binding.vpDrug.setVisibility(View.GONE);
            binding.homeDoctoeRv.setVisibility(View.GONE);
            binding.llSearch.setVisibility(View.GONE);

            String token = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.token, null);
            String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
            if (token == null && account_mobile == null && SharedPreferencesUtils.getInstance().getLoginTagBoolean(account_tagLoggedIn, false)) {
                binding.ivScan.setImageResource(R.mipmap.icon_scan_login);
            } else {
                binding.ivScan.setImageResource(R.mipmap.icon_scan_sacn);

            }
            binding.llScan.setVisibility(View.VISIBLE);
            binding.tlDrug.setVisibility(View.GONE);

            binding.llHomeInfoList.setBackgroundResource(R.drawable.bg_white);

            LinearLayout.LayoutParams qualifyFl = (LinearLayout.LayoutParams) binding.qualify.llQualify.getLayoutParams();
            qualifyFl.topMargin = ScreenUtils.dip2px(context, 92);
            binding.qualify.llQualify.setLayoutParams(qualifyFl);
        }
        binding.qualify.llQualify.setVisibility(View.VISIBLE);
        if (homeDoctorEntities.size() == 1) {
            //仅展示一个
            binding.homeDoctoeRv.setLayoutManager(new LinearLayoutManager(context));

//        } else if (homeDoctorEntities.size() == 2) {
//            //垂直展示
//            homeDoctoeRv.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
        } else {
            //纵向展示
            binding.homeDoctoeRv.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
        }
        if (homeDoctorEntities.size() > 0) {
            showGuide();
        }
        homeDoctorAdapter.notifyDataSetChanged();
        binding.homeDoctoeRv.scrollToPosition(clickHomeDoctorAdapterPosition);
    }

    //我的问诊数
    void refreshUIchargeOrderCount() {
        getRepository().queryPatientPendingCount(new HttpCallBack<PendingBean>() {
            @Override
            public void onSuccess(PendingBean s, int i) {
                if (s.isResult()) {
                    if (s.getData() != null && s.getData().getChargesCount() > 0) {
                        binding.homeChargeOrderCount.setVisibility(View.VISIBLE);
                        binding.homeChargeOrderCountRe.setVisibility(View.VISIBLE);
                        binding.homeChargeOrderCount.setText(s.getData().getChargesCount() <= 99 ? s.getData().getChargesCount() + "" : "99+");
                        binding.homeChargeOrderCountRe.setText(s.getData().getChargesCount() <= 99 ? s.getData().getChargesCount() + "" : "99+");
                    } else {
                        binding.homeChargeOrderCount.setVisibility(View.GONE);
                        binding.homeChargeOrderCountRe.setVisibility(View.GONE);
                    }

                    if (s.getData() != null && s.getData().getPrescriptionCount() > 0) {
                        binding.homePrescriptionCount.setVisibility(View.VISIBLE);
                        binding.homePrescriptionRe.setVisibility(View.VISIBLE);
                        binding.homePrescriptionCount.setText(s.getData().getPrescriptionCount() <= 99 ? s.getData().getPrescriptionCount() + "" : "99+");
                        binding.homePrescriptionRe.setText(s.getData().getPrescriptionCount() <= 99 ? s.getData().getPrescriptionCount() + "" : "99+");

                    } else {
                        binding.homePrescriptionCount.setVisibility(View.GONE);
                        binding.homePrescriptionRe.setVisibility(View.GONE);
                    }
                }
            }

            @Override
            public void onFailure(String s, int i) {

            }
        });
//        handler.post(new Runnable() {
//            @Override
//            public void run() {
//                if (TextUtils.isEmpty(chargeOrderCount) || chargeOrderCount.equals("0") || chargeOrderCount.isEmpty() || chargeOrderCount == null) {
//                    binding.homeChargeOrderCount.setVisibility(View.GONE);
//                    binding.homeChargeOrderCountRe.setVisibility(View.GONE);
//                } else {
//                    binding.homeChargeOrderCount.setVisibility(View.VISIBLE);
//                    binding.homeChargeOrderCountRe.setVisibility(View.VISIBLE);
//                    binding.homeChargeOrderCount.setText(chargeOrderCount);
//                    binding.homeChargeOrderCountRe.setText(chargeOrderCount);
//                }
//            }
//        });
    }

    public void toDrugListOTO() {
        if (homeDoctorEntities.size() == 0) {
            ALog.e("医生列表为空，无任何事件触发");
        } else {
            Bundle bundle = new Bundle();
            bundle.putString("id", homeDoctorEntities.get(0).getDoctorId() + "");
            bundle.putString("tabType", "o2o");
            HomeUtils.push(context, KitArouterConstants.CART_DOCTORBUNDLE, KitArouterConstants.Cart.Drug);
        }
    }

    public void showGuide() {
        String string = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_passportId, "");
        String tag = "patient_home_guide_" + string;
        if (!SharedPreferencesUtils.getInstance().getPop_Boolean(tag, false)) {
            SharedPreferencesUtils.getInstance().savePop(tag, true);
            NewbieGuide.with((Activity) context)
                    .setLabel("homeGuide")//设置引导层标示区分不同引导层，必传！否则报错
                    .setOnGuideChangedListener(new OnGuideChangedListener() {
                        @Override
                        public void onShowed(Controller controller) {
                            ALog.e("NewbieGuide onShowed");
                            //引导层显示
                        }

                        @Override
                        public void onRemoved(Controller controller) {
                            ALog.e("NewbieGuide onRemoved");
                            //引导层消失（多页切换不会触发）
                        }
                    })
                    .setOnPageChangedListener(new OnPageChangedListener() {
                        @Override
                        public void onPageChanged(int page) {
                            ALog.e("NewbieGuide onPageChanged");
                            //引导页切换，page为当前页位置，从0开始
                        }
                    })
                    .alwaysShow(true)//是否每次都显示引导层，默认false，只显示一次
                    .addGuidePage(//添加一页引导页
                            GuidePage.newInstance()//创建一个实例
//                                .addHighLight((ImageView) guide1.findViewById(R.id.home_guide_page1_img))//添加高亮的view
//                                .addHighLight(tvBottom, HighLight.Shape.RECTANGLE)
                                    .setLayoutRes(R.layout.guide_home_page1, R.id.home_guide_page1_next)//设置引导页布局
                                    .setEverywhereCancelable(false)//是否点击任意地方跳转下一页或者消失引导层，默认true
                                    .setOnLayoutInflatedListener(new OnLayoutInflatedListener() {
                                        @Override
                                        public void onLayoutInflated(View view) {
                                            //引导页布局填充后回调，用于初始化
                                            Glide.with(context).load(R.mipmap.img_home_guide_img1).into((ImageView) view.findViewById(R.id.home_guide_page1_img));
//                                        TextView tv = view.findViewById(R.id.textView2);
//                                        tv.setText("我是动态设置的文本");
                                        }
                                    })
//                                .setEnterAnimation(enterAnimation)//进入动画
//                                .setExitAnimation(exitAnimation)//退出动画
                    )
                    .addGuidePage(
                            GuidePage.newInstance()
                                    .setLayoutRes(R.layout.guide_home_page2, R.id.home_guide_page2_know)//引导页布局，点击跳转下一页或者消失引导层的控件id
                                    .setEverywhereCancelable(false)//是否点击任意地方跳转下一页或者消失引导层，默认true
                    )
                    .show();//显示引导层(至少需要一页引导页才能显示)
        }

    }

    void getXxxrUrl() {
        getRepository().getJumpUrl(SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_passportId, ""), new HttpCallBack<String>() {
            @Override
            public void onSuccess(String s, int i) {
                try {
                    JSONObject jsonObject = new JSONObject(s);
                    if (jsonObject.has("data") && !TextUtils.isEmpty(jsonObject.getString("data"))) {
                        ARouter.getInstance()
                                .build(ARouterConstants.MineWebviewActivity)
                                .withString("title", "心心向荣")
                                .withString("url", jsonObject.getString("data"))
                                .withBoolean("ishtml", false)
                                .navigation();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(String s, int i) {

            }
        });
    }

    void doThumbsUp(int id, int thumbs, int position) {
        getRepository().thumbsUp(id,thumbs, new HttpCallBack<ThumbsUpBean>() {
            @Override
            public void onSuccess(ThumbsUpBean s, int i) {
                if (s.isResult() && s.getData() != null) {
//                    refreshGoodUi(p, s);
                    healthNumberArticleDTOSArrayList.get(position).setThumbs(s.getData().getThumbs());
                    healthNumberArticleDTOSArrayList.get(position).setThumbsUp(s.getData().getThumbsUp());
                    binding.healthDoctorCard.doctorHealthVp.setAdapter(doctorHealthAdapter);
                    binding.healthDoctorCard.doctorHealthVp.setCurrentItem(position);
                }
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }

            @Override
            public void onFailure(String s, int i) {
                LoadingUtils.getLoadingUtils(context).dismissLoading();

            }
        });
    }

    void doThumbsDown(int id, int p) {
        getRepository().thumbsdown(id, new HttpCallBack<ThumbsUpBean>() {
            @Override
            public void onSuccess(ThumbsUpBean s, int i) {
                if (s.isResult() && s.getData() != null) {
                    refreshGoodUi(p, s);
                }
                LoadingUtils.getLoadingUtils(context).dismissLoading();

            }

            @Override
            public void onFailure(String s, int i) {
                LoadingUtils.getLoadingUtils(context).dismissLoading();
            }
        });
    }

    void refreshGoodUi(int p, ThumbsUpBean s) {
        healthNumberArticleDTOSArrayList.get(p).setThumbs(s.getData().getThumbs());
        healthNumberArticleDTOSArrayList.get(p).setThumbsUp(s.getData().getThumbsUp());
        doctorHealthAdapter = new DoctorHealthAdapter(healthNumberArticleDTOSArrayList, (Activity) context,
                binding.healthDoctorCard.doctorHealthVp,
                binding.healthDoctorCard.doctorHealthVpSign,
                onPagerClickListener).setInfiniteLoop(true);
        binding.healthDoctorCard.doctorHealthVp.setAdapter(doctorHealthAdapter);
        binding.healthDoctorCard.doctorHealthVp.setCurrentItem(p);
    }


    public void getSecretWord() {

        RequestParams params = new RequestParams();
        params.put("pageIndex", 1);
//        params.put("pageSize", 20);
        getRepository().getSecretWord(params, new HttpCallBack<SecretWordBean>() {
            @Override
            public void onSuccess(SecretWordBean wordBean, int code) {
                if (wordBean != null && wordBean.isResult() && wordBean.getData() != null && ListUtil.getSize(wordBean.getData().getDataList()) > 0) {
                    List<SecretWordBean.SecretWord> secretWords = wordBean.getData().getDataList();
                    refreshViewFlipper(binding.viewFlipper, secretWords);
                    refreshViewFlipper(binding.viewFlipperFixed, secretWords);
                } else {
                    refreshViewFlipper(binding.viewFlipper, null);
                    refreshViewFlipper(binding.viewFlipperFixed, null);
                }
            }

            @Override
            public void onFailure(String s, int i) {
                ALog.e("searchUI", "on failure: " + s + " " + i);
                refreshViewFlipper(binding.viewFlipper, null);
                refreshViewFlipper(binding.viewFlipperFixed, null);
            }
        });
    }

    void getNotify(String doctorId,int p){
        getRepository().notifyOpenCharge(doctorId,new HttpCallBack<BaseBean>(){
            @Override
            public void onSuccess(BaseBean s, int i) {
                if (s.isResult()){
                    ToastUtils.showShort("邀请成功，已为您提醒医生，敬请等待！");
                    homeDoctorEntities.get(p).setNotifyOpenCharge(true);
                    homeDoctorAdapter.notifyDataSetChanged();
                }
            }
            @Override
            public void onFailure(String s, int i) {
                BaseBean baseBean = new Gson().fromJson(s, BaseBean.class);
                if (baseBean!=null && !TextUtils.isEmpty(baseBean.getMsg())){
                    ToastUtils.showShort(baseBean.getMsg());
                }
            }
        });


    }

    public void getAgencyMatterStatisticsListData(){
        getRepository().getAgencyMatterStatisticsList(new HttpCallBack<AgencyMatterStatiesticsListBean>() {
            @Override
            public void onSuccess(AgencyMatterStatiesticsListBean s, int code) {
                if (s.isResult() && s.getData() != null){
                    if (s.getData().getAgencyMatterStatisticsList()!=null){
                        scheduleStrings.clear();
                        agencyMatterStatiesticsListBeans.clear();
                        agencyMatterStatiesticsListBeans.addAll(s.getData().getAgencyMatterStatisticsList());
                        for (int i = 0; i < agencyMatterStatiesticsListBeans.size(); i++) {
                            scheduleStrings.add(agencyMatterStatiesticsListBeans.get(i).getMessage());
                        }
                        binding.layoutSchedule.scheduleNoticeview.setNoticeList(scheduleStrings);
                        binding.layoutSchedule.scheduleNoticeNumber.setText(s.getData().getTotalQuantity() > 99 ? "99+" : s.getData().getTotalQuantity()+"");
                        if (s.getData().getAgencyMatterStatisticsList().size()>0){
                            binding.layoutSchedule.scheduleRl.setVisibility(View.VISIBLE);
                            if (s.getData().getAgencyMatterStatisticsList().size()>1){
                                binding.layoutSchedule.scheduleNoticeview.start();
                            }else{
                                binding.layoutSchedule.scheduleNoticeview.pause();
                            }
                        }else{
                            binding.layoutSchedule.scheduleRl.setVisibility(View.GONE);
                        }
                    }else{
                        ALog.e("agencyMatterStatisticsList is null");
                    }

                }
            }

            @Override
            public void onFailure(String s, int i) {

            }
        });
    }

}
